<?php
declare (strict_types = 1);

namespace app\model;

use think\Model;

/**
 * @mixin \think\Model
 */
class T_PM_MO_BASE extends Model
{
    public $table='T_PM_MO_BASE';
    public $connection='mysql';
    public function index($PROJECT_ID,$field=''){
        $sum=$this->where('PROJECT_ID',$PROJECT_ID)->where('INPUT_QTY>=OUTPUT_QTY')->sum("$field");
        return $sum;
    }
    public function produce($day,$order='asc'){
        $where3[]=['CREATE_TIME','>=',date('Y-m-d',strtotime('-'."$day".'day'))];
        $where3[]=['ACTUAL_ONLINE_TIME','<>',''];
        $list=$this->where($where3)->field('DATEDIFF(day,CREATE_TIME,ACTUAL_ONLINE_TIME) as time')->order('time',"$order")->find()->toArray();
        return $list;
    }
    public function zld_zz_avg($day,$order='asc'){
        $where4[]=['CREATE_TIME','>=',date('Y-m-d',strtotime('-'."$day".'day'))];
        $where4[]=['CLOSE_TIME','<>',''];
        $where4[]=['ACTUAL_START_TIME','<>',''];
        $list=$this->where($where4)->field('DATEDIFF(day,ACTUAL_START_TIME,CLOSE_TIME) as time')->order('time',"$order")->find()->toArray();
        return $list;
    }
}
